package Controller;

import org.jgroups.JChannel;
import org.jgroups.Message;
import org.jgroups.ReceiverAdapter;

public class ClientController extends ReceiverAdapter{
	
	
	JChannel chatControlCluster;
	
	String userName;
	
	public ClientController(String userName){
		
		this.userName = userName;
		
		try {

			// changer le port pour chaque connection 
			System.setProperty("jgroups.bind_addr", "127.0.0.1" );
			chatControlCluster = new JChannel();
			chatControlCluster.connect("chatControlCluster");
			
			
			
			chatControlCluster.setReceiver(this);
			
			Message msg=new Message();
			msg.setObject("Client message : Connection of user " + userName);
			send(msg);
			


			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public void send(Message msg){
		
		try {
			chatControlCluster.send(msg);
			System.out.println("1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("cicghjhjch");
	}
	
	public void receive(Message msg) {
		String mess = (String) msg.getObject();
		System.out.println("received : " + mess);
		if (mess.startsWith("|")) {

		}
	}


}
